|
|
|
|
|
|
|
Both of these methods are useful and appropriate in certain cases, but using the POST method with HTML forms is much more versatile. In the examples shown so far, you have only used the TEXT input field. However, there are many types of HTML form elements that can be used, such as radio buttons, drop-down boxes, and free-form text areas. One type of field that is very useful when dealing with database updates is a HIDDEN form field. A hidden form field is like a text field, but the user cannot see it or change its value. This type of field can be generated from an ASP page and sent down to the browser. When the user submits a form, the value of a hidden form field is sent back to the server with the other form fields. |
|
|
|
|
|
|
|
|
Revisit the example in Listings 31.3 and 31.4 and add edit capability for the author's name and birth year. In addition, you will consolidate all of the functionality from the previous example into subroutines in a single ASP page: |
|
|
|
|
|
|
|
|
AskForAuthors takes the place of DBQUERY.HTM. |
|
|
|
|
|
|
|
|
GetAuthorList replaces DBSEARCH.ASP. |
|
|
|
|
|
|
|
|
DisplayEditScreen is a new procedure, which displays a form that allows you to edit an author's information. |
|
|
|
|
|
|
|
|
UpdateDBInfo changes the database. |
|
|
|
|
|
|
|
|
The code for the new ASP page, AUTHOREDIT.ASP, is shown in Listing 31.5. |
|
|
|
|
|
|
|
|
Listing 31.5 ASPDEMO.ZIPASP Page Allowing Searching and Editing |
|
|
|
|
|
|
|
|
<HTML><BODY>
<%
Dim cn
Dim rs
Dim sSQL
Const MYASPNAME="authoredit.asp"
Sub AskForAuthors()
Response.Write ("<H1>Biblio Database Search</H1><HR>")
Response.Write ("<FORM ACTION=" & MYASPNAME & "?mode=search METHOD=POST>")
Response.Write ("Enter Author to search for:")
Response.Write ("<INPUT TYPE=TEXT NAME=txtSearch>")
Response.Write ("<INPUT TYPE=SUBMIT VALUE=""Click to Search"">")
Response.Write ("</FORM>")
End Sub
Sub GetAuthorList()
'CONNECT TO THE DATABASE AND PERFORM THE SEARCH
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DSN=BIBLIO"
sSQL = "SELECT * FROM AUTHORS WHERE AUTHOR LIKE "
sSQL = sSQL & "'" & Request.Form("txtSearch")
sSQL = sSQL & "%' ORDER BY AUTHOR"
Set rs = cn.Execute(sSQL) |
|
|
|
|
|